package com.hsy.swu.home.leftdrawer

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.TextView
import androidx.lifecycle.lifecycleScope
import com.hsy.swu.clouddb.LeanCloudHelper
import com.hsy.swu.databinding.ActivityQqGroupBinding
import com.hsy.swu.hsyutils.HsyActivity
import com.hsy.swu.hsyutils.HsyViewModel
import com.hsy.swu.hsyutils.MActivityUtil
import com.hsy.swu.hsyutils.MLog

class QQGroupActivity : HsyActivity<ActivityQqGroupBinding, HsyViewModel>() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        mBinding.tvMyQQ.setOnClickListener {
            toMyQQ()
        }

        mBinding.tvQQGroupId.setOnClickListener {
            MActivityUtil.clipText(
                it.context,
                it as TextView,
                "QQ群号已复制到剪贴版"
            )
            toQQGroup()
        }

        LeanCloudHelper.getInstance()?.showSubmitDialog(lifecycleScope)
    }

    private fun toQQGroup() {
        val intent = Intent().apply {
            data =
                Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26jump_from%3Dwebapi%26k%3DktIgDFHztBh4ZpVqAKp5YNyhcQlB1Ofs")
            addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
        }
        try {
            startActivity(intent)
        } catch (e: Exception) {
            MLog.attention(e.toString())
        }
    }

    private fun toMyQQ() {
        val intent = Intent().apply {
            data = Uri.parse("mqqwpa://im/chat?chat_type=wpa&uin=1619548883")
            addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
        }
        startActivity(intent)
    }
}